package com.lyy.photovoltaic.service.impl;

import com.lyy.photovoltaic.beans.OrdersDetails;
import com.lyy.photovoltaic.common.vo.ResultCode;
import com.lyy.photovoltaic.common.vo.ResultVO;
import com.lyy.photovoltaic.mapper.OrdersDetailsMapper;
import com.lyy.photovoltaic.service.OrdersDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class OrdersDetailsServiceImpl implements OrdersDetailsService {
    @Autowired
    OrdersDetailsMapper ordersDetailsMapper;

    @Override
    public ResultVO addOrdersDetails(OrdersDetails orderDetails) {
        int i = ordersDetailsMapper.insert(orderDetails);
        if (i > 0) {
            ResultVO resultVO = new ResultVO(ResultCode.SUCCESS, "插入订单详情成功", null);
            return resultVO;
        }
        return new ResultVO(ResultCode.FAILED, "插入订单详情失败", null);

    }

    @Override
    public ResultVO findOrderDetailsById(String ODId) {
//        System.out.println(ODId);
        OrdersDetails ordersDetails = ordersDetailsMapper.selectByPrimaryKey(ODId);
        if (ordersDetails == null) {
            return new ResultVO(ResultCode.FAILED, "查询订单详情失败", null);
        }
        ResultVO resultVO = new ResultVO(ResultCode.SUCCESS, "查询订单详情成功", ordersDetails);
        return resultVO;

    }

    @Override
    public ResultVO findOrderDetailsLists(String[] oDIds) {
//        System.out.println(oDIds);
        List<String> strings = Arrays.asList(oDIds);
//        System.out.println(strings);
        List<OrdersDetails> orderDetailsLists = ordersDetailsMapper.findOrderDetailsLists(oDIds);
//        System.out.println(orderDetailsLists);
        if (orderDetailsLists.size() > 0) {
//            System.out.println(orderDetailsLists.size());
//            System.out.println("234fdsdfg");
            ResultVO resultVO = new ResultVO(ResultCode.SUCCESS, "查询成功",orderDetailsLists);
            return resultVO;
        }
        return new ResultVO(ResultCode.FAILED,"查询失败",null);
    }

}
